﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using RATSharpW7.Model;
using RATSharp.Rest;
using System.Threading.Tasks;
using RATSharpW7.Converters;
using System.Collections.Generic;
namespace RATSharpW7.ViewModel
{
    public class CalendarViewModel : CollectionViewModel<DateTime, List<DateTime>>
    {
        private ColorConverter colorConverter;

        // Create the property that will be the source of the binding.
        public ColorConverter ColorConverter
        {
            get { return colorConverter; }
            set
            {
                colorConverter = value;
                // Call NotifyPropertyChanged when the source property 
                // is updated.
                RaisePropertyChanged("ColorConverter");
            }
        }

        public CalendarViewModel()
        {
            //colorConverter = new ColorConverter(this.DataSource);
        }

        public void loadCalendarOccupation(int month, int year) 
        {
            Task<Dates> task = RestService.getInstance().getDatesUserOccupation(month, year);
            notifyChangeModel(task);
        }

        protected void notifyChangeModel(Task<Dates> task)
        {
            task.ContinueWith(t =>
            {

                var list = t.Result;
                Exception ex = t.Exception;

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    //if (list != null)
                    //{
                    //    this.loadedObjectsDataSource.Clear();
                    //    foreach (Dates fav in list)
                    //    {
                    //      //  this.loadedObjectsDataSource.Add(fav);
                    //    }
                    //}
                });
            });
        }


    }
}
